package com.craftsman.tomcat.nio;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.QueryStringDecoder;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.InputStream;
import java.util.List;
import java.util.Map;


/**
 * request 对象 for nio
 * @author chenfanglin
 * @date 2021年05月15日
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BXNIORequest {

    private ChannelHandlerContext context;

    private HttpRequest request;

    private String method;

    private String url;


    public BXNIORequest(ChannelHandlerContext context,HttpRequest request)throws Exception{

        this.context=context;
        this.request=request;

    }

    public Map<String, List<String>> getParameters(){
        QueryStringDecoder decoder=new QueryStringDecoder(request.uri());
        return decoder.parameters();
    }

    public String getParameter(String name){
        Map<String,List<String>> params=getParameters();
        List<String> param=params.get(name);
        if(null==param){
            return null;
        }
        return param.get(0);
    }

}
